//: [Previous](@previous)

import Foundation
/*
let age = 20
if age > 18 {
	print("成年了")
}

let score = 61
if score>60 {
	 print("及格")
} else {
	 print("不及格")
}

*/

/*
let score:Int? = 61
if score ??  0>60 {
	print("score is: \(score ?? 0 + 0)")
} else {
	 print("不及格")
}
*/

/*
let score:Int? = 61
if score!>60 {
	print("score is: \(score!+0)")
} else {
	 print("不及格")
}
*/

//let score:Int? = 61
//if let newScore = score  {
//	if(newScore>60){
//		print("及格了：\(newScore) 分")
//	}else {
//		print("不及格")
//	}
//}


// ------推荐用法-----------
/*
let score:Int? = 61
if let score = score {
	if score>60 {
		print("及格了：\(score) 分")
	}else {
		print("不及格")
	}
}
*/

//let score:Int? = 61
//if score != nil {
//	if score! > 60 {
//		print("及格了")
//	}else {
//		print("不格了")
//	}
//}else {
//	print("什么都没有")
//}


// ------终结写法-----------
/**
let score:Int? = 61
if let score=score,score>60 {
	print("及格了\(score)")
}else {
	print("不及格")
}
*/



/*
func checkUsername(username: String) {
	guard username=="admin" else {
		print("你不是管理员，没有权限")
		return
	}
	print("欢迎你，管理员：\(username)")
}
checkUsername(username: "Jack Ma")  //不是管理员，没有权限
checkUsername(username: "admin")  //欢迎你，管理员：admin
*/

/*
func checkUsername(username: String?) {
	guard let username = username, username=="admin" else {
		print("你不是管理员，没有权限")
		return
	}
	print("欢迎你，管理员：\(username)")
}
checkUsername(username: "Jack Ma")  //不是管理员，没有权限
checkUsername(username: "admin")  //欢迎你，管理员：admin
checkUsername(username: nil)  //你不是管理员，没有权限
*/


//let name = "admin"
//switch name {
//case "Jack":
//	print("Jack")
//case "admin":
//	print("Admin")
//default:
//	print("Not Jack,not Admin")
//}

/*
let score = 60
switch score {
case 0:
	print("Zero,傻瓜")
case 1..<60:
	print("不及格")
case 60..<70:
	print("及格")
case 70..<90:
	print("良好")
case 90...100:
	print("优秀")
default:
	print("翻天了")
}
*/

/*
let somePoint = (1, 1)
switch somePoint {
case (0, 0):
    print("(0, 0) is at the origin")
case (_, 0):
    print("(\(somePoint.0), 0) is on the x-axis")
case (0, _):
    print("(0, \(somePoint.1)) is on the y-axis")
case (-2...2, -2...2):
    print("(\(somePoint.0), \(somePoint.1)) is inside the box")
default:
    print("(\(somePoint.0), \(somePoint.1)) is outside of the box")
}
*/
// prints "(1, 1) is inside the box"


/*
enum DireactionModel {
	case East,South, West,North
}
let direction = DireactionModel.East
switch direction {
case .East:
	print("东方")
case .South:
	print("南方")
case .West:
	print("西方")
case .North:
	print("北方")
}
*/

/*
let value = "1"
switch(value) {
case "1":
  print("go")
	fallthrough
case "2":
	print("go")
	fallthrough
default:
  print("go")
}
*/


// 遍历数组
//let names = ["Anna", "Alex", "Brian", "Jack"]
//for name in names {
//    print("Hello, \(name)!")
//}
// Hello, Anna!
// Hello, Alex!
// Hello, Brian!
// Hello, Jack!


// 遍历字典
//let numberOfLegs = ["spider": 8, "ant": 6, "cat": 4]
//for (animalName, legCount) in numberOfLegs {
//    print("\(animalName)s have \(legCount) legs")
//}
// ants have 6 legs
// cats have 4 legs
// spiders have 8 legs
//numberOfLegs.enumerated()
//
//
//for i in 0...2 {
//	print(i)
//}
// Both print:
// 0
// 1
// 2


//for (n, c) in "Swift".enumerated() {
//    print("\(n): '\(c)'")
//}
// Prints "0: 'S'"
// Prints "1: 'w'"
// Prints "2: 'i'"
// Prints "3: 'f'"
// Prints "4: 't'"


//var i: Int = 0
//repeat {
//   print(i)
//	 i += 1
//} while i < 3
//
//
//var num = 1
//while num < 3 {
//	print("num:\(num)")
//	num += 1
//}


//let students = ["Jack":13,"Lucy":59,"Jim":88,"Tom":90]
//for (name,score) in students where score<60 {
//	print("\(name) 不及格")
//}

let arr = [1,2,3,4]
arr.forEach{
	print($0)
}
// 等同于
arr.forEach {
	num in
	print(num)
}
//: [Next](@next)
